const http = require('http')
const fs = require('fs')

const server = http.createServer((request, response) => {
    let html = fs.readFileSync(__dirname + '/index.html')
    let css = fs.readFileSync(__dirname + '/index.css')
    let script = fs.readFileSync(__dirname + '/index.js')
    let {pathname} = new URL(request.url, 'http://127.0.0.1')
    console.log(pathname)
    if(pathname==='/'){
        response.end(html)
    }else if(pathname==='/index.js'){
        response.end(script)
    }else if(pathname==='/index.css'){
        response.end(css)
    }else {
        response.end(`<h1>Not Found</h1>`)
    }


})
server.listen(9090, () => {
    console.log('服务启动')
})